<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/gallery/om/Gallery.php");



/**
 * BaseGalleryForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseGalleryForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * gallery
     *
     * @var Gallery 
     */
    protected $gallery;


    /**
     * formImage
     *
     * @var mixed 
     */
    protected $formImage;


    /**
     * deleteImage
     *
     * @var mixed 
     */
    protected $deleteImage;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseGalleryForm
     */
    public function __construct() {
        $this->gallery = new Gallery();
        $this->formImage = null;
        $this->deleteImage = false;
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get Gallery
     *
     * @return Gallery 
     */
    public function getGallery() {
        return $this->gallery;
    }


    /**
     * Set Gallery
     *
     * @param Gallery  gallery
     */
    public function setGallery(Gallery $gallery) {
        $this->gallery = $gallery;
    }


    /**
     * Get FormImage
     *
     * @return mixed 
     */
    public function getFormImage() {
        return $this->formImage;
    }


    /**
     * Set FormImage
     *
     * @param mixed  formImage
     */
    public function setFormImage($formImage) {
        $this->formImage = $formImage;
    }


    /**
     * Get DeleteImage
     *
     * @return mixed 
     */
    public function getDeleteImage() {
        return $this->deleteImage;
    }


    /**
     * Set DeleteImage
     *
     * @param mixed  deleteImage
     */
    public function setDeleteImage($deleteImage) {
        $this->deleteImage = $deleteImage;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        if(is_null($this->getGallery()->getName()) || strlen($this->getGallery()->getName()) == 0)
            $errors->add("gallery->name",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.name", true)));


        if(!is_null($this->getGallery()->getName()) && strlen($this->getGallery()->getName()) > 0 && strlen($this->getGallery()->getName()) > 255)
            $errors->add("gallery->name",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.name", true),
                    new ActionMessage("255", false))));


        if(!is_null($this->getGallery()->getType()) && strlen($this->getGallery()->getType()) > 0 && strlen($this->getGallery()->getType()) > 64)
            $errors->add("gallery->type",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.type", true),
                    new ActionMessage("64", false))));


        return $errors;
    }

}
?>